﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SAM.Javascript.Test
{
    class Program
    {

        private static SAM.Framework.Plugins.IPlugin plugin;

        static void Main(string[] args)
        {
            Init();

            MockTest();

            Console.ReadKey();
        } 

        static void Init()
        {
            string[] jsFiles = { "jsLib\\mock.js" };
            plugin = new SAM.JavaScript.V8.V8ExecuteForThirdPart(jsFiles);
            plugin.Install();
        }

        static void BasicTest()
        {
            SAM.Framework.Javascript.IExecute execute = plugin as SAM.Framework.Javascript.IExecute;
            SAM.Framework.Javascript.ResultInfo resultInfo = execute.Execute("\r\n var result=Mock.mock('@email')");
            resultInfo = execute.Execute("\r\n var result=result");
            Console.WriteLine(resultInfo.Content["result"]);
        }

        static void HostTypeTest()
        {
            SAM.Framework.Javascript.IExchange exchange = plugin as SAM.Framework.Javascript.IExchange;
            SAM.Framework.Javascript.IExecute execute = plugin as SAM.Framework.Javascript.IExecute;

            MockInfo mockInfo = new MockInfo();
            exchange.AddHostObject("result", mockInfo);

            string jsMockInfo = " var _result={\"Name|1\":\"@cname\",\"Email|2\":\"c\"}; result.Name = _result.Name; result.Email = _result.Email;  ";
            execute.ExecuteNonResult(jsMockInfo);

        }

        static void MockTest()
        {
            SAM.MockData.DefaultMockData defaultMockData = new MockData.DefaultMockData(plugin as SAM.Framework.Javascript.IExecute, plugin as SAM.Framework.Javascript.IExchange);
            var mockStr = "{\"Name|1\":\"@cname\",\"Email|2\":\"c\"}";
            var value = defaultMockData.Mock<MockInfo>(mockStr);
            Console.WriteLine(value.Name + ":" + value.Email);
        }

        public class MockInfo
        {
            public string Name { get; set; }

            public string Email { get; set; }
        }
    }
}
